<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="时间">
        <el-date-picker
          v-model="daterangeYearyf"
          style="width: 240px"
          value-format="yyyy-MM"
          type="monthrange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8"  style="text-align: center;font-size: 50px;"> 
          收入支出统计汇总表
  </el-row>
    <el-row type="flex" justify="end">
    <el-col :span="3" style="font-size: 50px; color: red;">
      内部资料
    </el-col>
  </el-row>
  <el-row type="flex" justify="end">
    <el-col :span="5">
      单位(万元)
    </el-col>
  </el-row>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:jyjcAllSumList:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="jyjcAllSumListList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="时间" align="center" prop="yearyf" width="180">
      </el-table-column> -->
      <el-table-column label="经济科目" align="center" prop="jjkm" />
      <el-table-column label="总体合计" align="center" prop="zthj"  :formatter="formatToTenThousand" />
      <el-table-column label="六部一所合计" align="center" prop="lbyshj" :formatter="formatToTenThousand" />
      <el-table-column label="办公室(党群工作部)" align="center" prop="bgs"  :formatter="formatToTenThousand"/>
      <el-table-column label="人力资源部" align="center" prop="rlzy" :formatter="formatToTenThousand"/>
      <el-table-column label="财务内审部" align="center" prop="cw" :formatter="formatToTenThousand" />
      <el-table-column label="市场拓展部(业务协作部)" align="center" prop="sctz" :formatter="formatToTenThousand" />
      <el-table-column label="质量管理部" align="center" prop="zlgl" :formatter="formatToTenThousand"/>
      <el-table-column label="设备管理部" align="center" prop="sbgl" :formatter="formatToTenThousand"/>
      <el-table-column label="科技规划研究所" align="center" prop="kjghyjs" :formatter="formatToTenThousand"  />
      <el-table-column label="专业所合计" align="center" prop="zyshj" :formatter="formatToTenThousand"/>
      <el-table-column label="计量科学研究所" align="center" prop="jls" :formatter="formatToTenThousand" />
      <el-table-column label="标准研究所" align="center" prop="bzs" :formatter="formatToTenThousand" />
      <el-table-column label="特种设备检验技术研究所" align="center" prop="tzs" :formatter="formatToTenThousand"/>
      <el-table-column label="产品质量检验技术研究所" align="center" prop="cps" :formatter="formatToTenThousand"/>
      <el-table-column label="纤维质量监测研究所" align="center" prop="xws" :formatter="formatToTenThousand" />
      <el-table-column label="食品与粮食检验技术研究所" align="center" prop="sps" :formatter="formatToTenThousand"/>
      <el-table-column label="药品检验技术研究所" align="center" prop="yps" :formatter="formatToTenThousand"/>
      <el-table-column label="医疗器械检验技术研究所" align="center" prop="yls" />
      <el-table-column label="农产品与农药土壤肥料检验技术研究所" align="center" prop="ncp" :formatter="formatToTenThousand" />
      <el-table-column label="畜牧与水产品检验技术研究所" align="center" prop="xms" :formatter="formatToTenThousand" />
      <el-table-column label="能源产品检验技术研究所" align="center" prop="nys" :formatter="formatToTenThousand"/>
      <el-table-column label="度量衡检定所" align="center" prop="dls" :formatter="formatToTenThousand"/>
      <el-table-column label="计算合计" align="center" prop="jshj" :formatter="formatToTenThousand"/>
      <el-table-column label="职能部门分摊" width="100"   align="center" :show-overflow-tooltip="true" prop="mark1" />
      <el-table-column label="专业所独立行使事项" width="100"  align="center"  :show-overflow-tooltip="true" prop="mark2" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listJyjcAllSumList, getJyjcAllSumList, delJyjcAllSumList, addJyjcAllSumList, updateJyjcAllSumList } from "@/api/system/jyjcAllSumList"

export default {
  name: "JyjcAllSumList",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 财务收入支出统计表格数据
      jyjcAllSumListList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 排序时间范围
      daterangeYearyf: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        yearyf: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询财务收入支出统计列表 */
    getList() {
      this.loading = true
      this.queryParams.params = {}
      if (null != this.daterangeYearyf && '' != this.daterangeYearyf) {
        this.queryParams.params["beginYearyf"] = this.daterangeYearyf[0]
        this.queryParams.params["endYearyf"] = this.daterangeYearyf[1]
      }
      listJyjcAllSumList(this.queryParams).then(response => {
        this.jyjcAllSumListList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        year: null,
        yf: null,
        yearyf: null,
        deptname: null,
        deptcode: null,
        jjkm: null,
        expenseType: null,
        zthj: null,
        lbyshj: null,
        bgs: null,
        rlzy: null,
        cw: null,
        sctz: null,
        zlgl: null,
        sbgl: null,
        kjghyjs: null,
        zyshj: null,
        jls: null,
        bzs: null,
        tzs: null,
        cps: null,
        xws: null,
        sps: null,
        yps: null,
        yls: null,
        ncp: null,
        xms: null,
        nys: null,
        dls: null,
        jshj: null,
        mark1: null,
        mark2: null,
        orderNum: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeYearyf = []
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.year)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加财务收入支出统计"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const year = row.year || this.ids
      getJyjcAllSumList(year).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改财务收入支出统计"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.year != null) {
            updateJyjcAllSumList(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addJyjcAllSumList(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const years = row.year || this.ids
      this.$modal.confirm('是否确认删除财务收入支出统计编号为"' + years + '"的数据项？').then(function() {
        return delJyjcAllSumList(years)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/jyjcAllSumList/export', {
        ...this.queryParams
      }, `jyjcAllSumList_${new Date().getTime()}.xlsx`)
    },  
    formatToTenThousand(row, column, cellValue) {
      console.info(cellValue);
      if (cellValue === null || cellValue === undefined) return '-'
      return (cellValue / 10000).toFixed(2) 
    }
  }
}
</script>
